#!/bin/env python

import time
import cv2
import numpy as np

pic_path = "../resource/pic/img_001.jpg"
windowName = pic_path

pic1 = cv2.imread(pic_path)
pic1_h, pic1_w, pic1_chn = pic1.shape

# 创建卷积核
kernel = np.ones((5, 5), np.float32) / 25
# 对图片卷积操作
img = cv2.filter2D(pic1, -1, kernel)

# 卷积核突出轮廓
kernel = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
img1 = cv2.filter2D(pic1, -1, kernel)

# 卷积核 浮雕效果
kernel = np.array([[-2, 1, 0], [-1, 1, 1], [0, 1, 2]])
gray_img = cv2.cvtColor(pic1, cv2.COLOR_BGR2GRAY)
img2 = cv2.filter2D(gray_img, -1, kernel)

cv2.namedWindow("gray_img", cv2.WINDOW_NORMAL)
cv2.resizeWindow("gray_img", 1500, 500)
cv2.imshow("gray_img", np.hstack((gray_img, img2)))

# 卷积核 锐化
kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]])
img3 = cv2.filter2D(pic1, -1, kernel)

cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
cv2.resizeWindow(windowName, 2000, 500)
cv2.imshow(windowName, np.hstack((pic1, img, img1, img3)))

while True:
    if cv2.waitKey(0) == ord('q'):
        break

print('销毁窗口')
cv2.destroyAllWindows()


